package com.kenai.jbosh;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.lang.ref.SoftReference;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;

final class BodyParserSAX
  implements BodyParser
{
  private static final Logger LOG = Logger.getLogger(BodyParserSAX.class.getName());
  private static final ThreadLocal<SoftReference<SAXParser>> PARSER = new ThreadLocal()
  {
    protected SoftReference<SAXParser> initialValue()
    {
      return new SoftReference(null);
    }
  };
  private static final SAXParserFactory SAX_FACTORY = SAXParserFactory.newInstance();

  static
  {
    SAX_FACTORY.setNamespaceAware(true);
    SAX_FACTORY.setValidating(false);
  }

  // ERROR //
  private static SAXParser getSAXParser()
  {
    // Byte code:
    //   0: getstatic 51	com/kenai/jbosh/BodyParserSAX:PARSER	Ljava/lang/ThreadLocal;
    //   3: invokevirtual 66	java/lang/ThreadLocal:get	()Ljava/lang/Object;
    //   6: checkcast 68	java/lang/ref/SoftReference
    //   9: invokevirtual 69	java/lang/ref/SoftReference:get	()Ljava/lang/Object;
    //   12: checkcast 71	javax/xml/parsers/SAXParser
    //   15: astore_0
    //   16: aload_0
    //   17: ifnonnull +53 -> 70
    //   20: getstatic 37	com/kenai/jbosh/BodyParserSAX:SAX_FACTORY	Ljavax/xml/parsers/SAXParserFactory;
    //   23: invokevirtual 74	javax/xml/parsers/SAXParserFactory:newSAXParser	()Ljavax/xml/parsers/SAXParser;
    //   26: astore 4
    //   28: new 68	java/lang/ref/SoftReference
    //   31: dup
    //   32: aload 4
    //   34: invokespecial 77	java/lang/ref/SoftReference:<init>	(Ljava/lang/Object;)V
    //   37: astore 5
    //   39: getstatic 51	com/kenai/jbosh/BodyParserSAX:PARSER	Ljava/lang/ThreadLocal;
    //   42: aload 5
    //   44: invokevirtual 80	java/lang/ThreadLocal:set	(Ljava/lang/Object;)V
    //   47: aload 4
    //   49: areturn
    //   50: astore_3
    //   51: aload_3
    //   52: astore_2
    //   53: new 82	java/lang/IllegalStateException
    //   56: dup
    //   57: ldc 84
    //   59: aload_2
    //   60: invokespecial 87	java/lang/IllegalStateException:<init>	(Ljava/lang/String;Ljava/lang/Throwable;)V
    //   63: athrow
    //   64: astore_1
    //   65: aload_1
    //   66: astore_2
    //   67: goto -14 -> 53
    //   70: aload_0
    //   71: invokevirtual 90	javax/xml/parsers/SAXParser:reset	()V
    //   74: aload_0
    //   75: areturn
    //   76: astore_1
    //   77: goto -12 -> 65
    //   80: astore_3
    //   81: goto -30 -> 51
    //
    // Exception table:
    //   from	to	target	type
    //   20	39	50	javax/xml/parsers/ParserConfigurationException
    //   20	39	64	org/xml/sax/SAXException
    //   39	47	76	org/xml/sax/SAXException
    //   39	47	80	javax/xml/parsers/ParserConfigurationException
  }

  public BodyParserResults parse(String paramString)
    throws BOSHException
  {
    BodyParserResults localBodyParserResults = new BodyParserResults();
    try
    {
      ByteArrayInputStream localByteArrayInputStream = new ByteArrayInputStream(paramString.getBytes());
      SAXParser localSAXParser = getSAXParser();
      localSAXParser.parse(localByteArrayInputStream, new Handler(localSAXParser, localBodyParserResults, null));
      return localBodyParserResults;
    }
    catch (SAXException localSAXException)
    {
      localObject = localSAXException;
      throw new BOSHException("Could not parse body:\n" + paramString, (Throwable)localObject);
    }
    catch (IOException localIOException)
    {
      while (true)
        Object localObject = localIOException;
    }
  }

  private static final class Handler extends DefaultHandler
  {
    private String defaultNS = null;
    private final SAXParser parser;
    private final BodyParserResults result;

    private Handler(SAXParser paramSAXParser, BodyParserResults paramBodyParserResults)
    {
      this.parser = paramSAXParser;
      this.result = paramBodyParserResults;
    }

    public void startElement(String paramString1, String paramString2, String paramString3, Attributes paramAttributes)
    {
      if (BodyParserSAX.LOG.isLoggable(Level.FINEST))
      {
        BodyParserSAX.LOG.finest("Start element: " + paramString3);
        BodyParserSAX.LOG.finest("    URI: " + paramString1);
        BodyParserSAX.LOG.finest("    local: " + paramString2);
      }
      BodyQName localBodyQName1 = AbstractBody.getBodyQName();
      if ((!localBodyQName1.getNamespaceURI().equals(paramString1)) || (!localBodyQName1.getLocalPart().equals(paramString2)))
        throw new IllegalStateException("Root element was not '" + localBodyQName1.getLocalPart() + "' in the '" + localBodyQName1.getNamespaceURI() + "' namespace.  (Was '" + paramString2 + "' in '" + paramString1 + "')");
      for (int i = 0; ; i++)
      {
        if (i >= paramAttributes.getLength())
        {
          this.parser.reset();
          return;
        }
        String str1 = paramAttributes.getURI(i);
        if (str1.length() == 0)
          str1 = this.defaultNS;
        String str2 = paramAttributes.getLocalName(i);
        String str3 = paramAttributes.getValue(i);
        if (BodyParserSAX.LOG.isLoggable(Level.FINEST))
          BodyParserSAX.LOG.finest("    Attribute: {" + str1 + "}" + str2 + " = '" + str3 + "'");
        BodyQName localBodyQName2 = BodyQName.create(str1, str2);
        this.result.addBodyAttributeValue(localBodyQName2, str3);
      }
    }

    public void startPrefixMapping(String paramString1, String paramString2)
    {
      if (paramString1.length() == 0)
      {
        if (BodyParserSAX.LOG.isLoggable(Level.FINEST))
          BodyParserSAX.LOG.finest("Prefix mapping: <DEFAULT> => " + paramString2);
        this.defaultNS = paramString2;
      }
      while (!BodyParserSAX.LOG.isLoggable(Level.FINEST))
        return;
      BodyParserSAX.LOG.info("Prefix mapping: " + paramString1 + " => " + paramString2);
    }
  }
}

/* Location:           C:\Users\user\Desktop\dd28_pcdd720\classes_dex2jar.jar
 * Qualified Name:     com.kenai.jbosh.BodyParserSAX
 * JD-Core Version:    0.6.2
 */